<?php

namespace App\Http\Services;

use App\Http\Model\Hint;
use App\Http\Model\OutJson;
use App\Http\Model\ShareSendGoods;
use App\Http\Model\User;

class RegisterServices extends CommonServices
{

    protected $mall_head = 138;//头饰
    protected $mall_bubble = 133;//气泡
    protected $send_day = 7;//赠送天数
    protected $sendGoodsModel;
    protected $userModel;

    public function __construct(ShareSendGoods $shareSendGoods, User $user)
    {
        $this->sendGoodsModel = $shareSendGoods;
        $this->userModel = $user;
    }
//    private $action =
    /*
     * 发送注册接口
     * @param [$phone]   注册电话
     * @param [$sms_code]   发送验证码
     * @param [$password]   注册密码
     * @param [$invite_uid]   邀请者id
     * */
    public function send_register($phone, $sms_code, $password, $invite_uid)
    {
        $data['phone'] = $phone;
        $data['sms_code'] = $sms_code;
        $data['password'] = $password;
        $data['invite_uid'] = $invite_uid;
        $action = env('KK_API_HOST') . "/user/phone/register";
        return curl_request($action, $data);
    }


    /*
         * api接口
         * @param [$user_id]   赠送用户id
         * */
    public function clickAwardGoods($new_uid)
    {
        //获取新用户id
        if (!$new_uid) {
            return false;
        }
        $checkUser = $this->userModel->showUserInvite($new_uid);
        if (!$checkUser) return false;
        //查看是否赠送
        $send_log = $this->sendGoodsModel->sendUserLog($new_uid, ['1', '3']);
        if ($send_log) return false;

        //获取配置
        // 主框架赠送商品api
        $bubble_data = [
            'user_id' => $new_uid,
            'goods_id' => $this->mall_bubble,
            'goods_type' => 3,
            'time_limit' => $this->send_day,
        ];

        // 主框架赠送商品api
        $curl_bubble = json_decode(curl_request(env('KK_API_HOST') . '/mall/goods/give_user', $bubble_data), true);
        if ($curl_bubble['code'] == 0) $this->sendGoodsModel->createSendGoodsLog($bubble_data);
        $headwear_data = [
            'user_id' => $new_uid,
            'goods_id' => $this->mall_head,
            'goods_type' => 3,
            'time_limit' => $this->send_day,
        ];
        $curl_headwear = json_decode(curl_request(env('KK_API_HOST') . '/mall/goods/give_user', $headwear_data), true);
        if ($curl_headwear['code'] == 0) $this->sendGoodsModel->createSendGoodsLog($headwear_data);
        $msg_data['user_id'] = $new_uid;
        $msg_data['msg'] = "您的新人超值福利 头饰+气泡已到账";
        curl_request(env('KK_API_HOST') . '/msg/text', $msg_data);
        return true;
    }


}